#============================================
# #知识点 
import socket
from multiprocessing import Process
from threading import Thread
server =socket.socket() # 括号内不加参数默认就是TCP协议
server. bind(('127.0.0.1' ,8080))
server.listen(5)
#将服务的代码 单独封装成一个函数
def talk(conn) :
    #通信循环
    while True:
        try:
            data = conn. recv( 1024)
            #针对mac linux客户端断开链接后
            if len(data) == 0: break
            print (data .decode( 'utf-8' ))
            conn. send(b'HTTP/1.1 200 OK\r\n\r\n')
            conn. send(data. upper() )
        except ConnectionResetError as e:
            # print(e)
            break
    conn.close( )
#链接循环
while True:
    conn, addr = server.accept() # 接客
    #叫其他人来服务客户
    t=Thread(target=talk, args=(conn,))
    # t = Process(target=talk, args=( conn,))
    t.start()

# "客户端”
# import socket
# client = socket. socket()
# client. connect( ( '127.0.0.1' ,8080) )
# while True:
# client.send(b'hello world' ) 
# data = client . recv(1024)
# print (data . decode( 'utf-8'))
#============================================
